import React, {useEffect, useState} from 'react';
import {
  View,
  Text,
  TouchableOpacity,
  ActivityIndicator,
  FlatList,
  Image,
  TextInput,
} from 'react-native';
import {useNavigation} from '@react-navigation/native';
import AreaView from '../../components/Layout/AreaView';
import CommentInput from '../../components/CommentInput';
import styles from './style';
import {inquiryList} from '../../service/user';
import BaseUrl from '../../config/BaseUrl';

const TopicDetail = (props) => {
  const {
    route: {
      params: {type},
    },
  } = props;

  const navigation = useNavigation();
  const [topicList, setTopicList] = useState([]);

  useEffect(() => {
    inquiryList({type: type, pn: 1, ps: 10}).then((res) => {
      console.log(type);
      console.log(res);
      setTopicList(res.rows);
    });
  }, []);
  return (
    <AreaView>
      <View style={styles.topic_container}>
        {topicList?.map((item) => (
          <TouchableOpacity
            activeOpacity={1}
            key={item.id}
            onPress={() => {
              navigation.push('TopicDetail', {
                id: item?.id,
              });
            }}>
            <View style={styles.head_container}>
              <Image
                style={styles.avatar}
                source={{uri: BaseUrl.imgurl + item.portrait}}
              />
              <View style={styles.name_time}>
                <View style={styles.name_time_top}>
                  <Text style={styles.name_text}>{item.createdName}</Text>
                  <Text style={styles.time_t_text}>{item.createdTime}</Text>
                </View>
              </View>
            </View>
            <View style={styles.topic_content}>
              <Text style={styles.content_text}>#精选问题# {item.title}</Text>
            </View>
          </TouchableOpacity>
        ))}
      </View>
    </AreaView>
  );
};

export default TopicDetail;
